using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQOPUNKT
    {
        public DataRow Convert2QOPUNKT(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQOPUNKT(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["QOTMANDANT"] = " ".PadRight(2 ); 
         dwReturn["QOTPNRKRS"] = " ".PadRight(2 ); 
         dwReturn["QOTPLFDNR"] = " ".PadRight(6 ); 
         dwReturn["QOTPSTEP"] = " ".PadRight(4 ); 
         dwReturn["QOTLFDNR"] = " ".PadRight(9 ); 
         dwReturn["QOTNEUB"] = " ".PadRight(8 ); 
         dwReturn["QOTNEUD"] = " ".PadRight(0 ); 
         dwReturn["QOTAENB"] = " ".PadRight(8 ); 
         dwReturn["QOTAEND"] = " ".PadRight(0 ); 
         dwReturn["QOTAENZL"] = " ".PadRight(0 ); 
         dwReturn["QOTARTST"] = " ".PadRight(1 ); 
         dwReturn["QOTKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["QOTWERK"] = " ".PadRight(3 ); 
         dwReturn["QOTABT"] = " ".PadRight(3 ); 
         dwReturn["QOTART"] = " ".PadRight(20 ); 
         dwReturn["QOTVAR"] = " ".PadRight(3 ); 
         dwReturn["QOTFARBE"] = " ".PadRight(10 ); 
         dwReturn["QOTCOLORIT"] = " ".PadRight(10 ); 
         dwReturn["QOTDESSIN"] = " ".PadRight(10 ); 
         dwReturn["QOTBESCH"] = " ".PadRight(10 ); 
         dwReturn["QOTZUSTAND"] = " ".PadRight(4 ); 
         dwReturn["QOTGROE"] = " ".PadRight(7 ); 
         dwReturn["QOTPRSFE"] = " ".PadRight(0 ); 
         dwReturn["QOTPREINHT"] = " ".PadRight(2 ); 
         dwReturn["QOTEINHEIT"] = " ".PadRight(15 ); 
         dwReturn["QOTPRSTK"] = " ".PadRight(0 ); 
         dwReturn["QOTAUFTYP"] = " ".PadRight(1 ); 
         dwReturn["QOTAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["QOTAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["QOTAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["QOTTP"] = " ".PadRight(4 ); 
         dwReturn["QOTANZEINH"] = " ".PadRight(0 ); 
         dwReturn["QOTANZPR"] = " ".PadRight(0 ); 
         dwReturn["QOTANZAKT"] = " ".PadRight(0 ); 
         dwReturn["QOTSKIPLOS"] = " ".PadRight(0 ); 
         dwReturn["QOTZEILE"] = " ".PadRight(0 ); 
         dwReturn["QOTSPALTE"] = " ".PadRight(0 ); 
         dwReturn["QOTORDER"] = " ".PadRight(9 ); 
         dwReturn["QOTOSTEP"] = " ".PadRight(4 ); 
         dwReturn["QOTORESULT"] = " ".PadRight(1 ); 
         dwReturn["QOTSRESULT"] = " ".PadRight(1 ); 
         dwReturn["QOTRORDER"] = " ".PadRight(9 ); 
         dwReturn["QOTRSTEP"] = " ".PadRight(4 ); 
         dwReturn["QOTAFOLGE"] = " ".PadRight(3 ); 
         dwReturn["QOTFILLER"] = " ".PadRight(38 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQOPUNKT(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQOPUNKT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQOPUNKT(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQOPUNKT(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQOPUNKT(dwLocal, ITXDBVERSION);
            }
            UpdateQOPUNKT(dwLocal);
        }
        public void InsertQOPUNKT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QOPUNKT(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQOPUNKT(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QOPUNKT WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QOPUNKT  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QOPUNKT";
            Return = Result;
            return Return;
        }
        public void DeleteQOPUNKT(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QOPUNKT   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQOPUNKT(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QOPUNKT SET "
                    +"QOTMANDANT= :QOTMANDANT,"
                    +"QOTPNRKRS= :QOTPNRKRS,"
                    +"QOTPLFDNR= :QOTPLFDNR,"
                    +"QOTPSTEP= :QOTPSTEP,"
                    +"QOTLFDNR= :QOTLFDNR,"
                    +"QOTNEUB= :QOTNEUB,"
                    +"QOTNEUD= :QOTNEUD,"
                    +"QOTAENB= :QOTAENB,"
                    +"QOTAEND= :QOTAEND,"
                    +"QOTAENZL= :QOTAENZL,"
                    +"QOTARTST= :QOTARTST,"
                    +"QOTKUNDNR= :QOTKUNDNR,"
                    +"QOTWERK= :QOTWERK,"
                    +"QOTABT= :QOTABT,"
                    +"QOTART= :QOTART,"
                    +"QOTVAR= :QOTVAR,"
                    +"QOTFARBE= :QOTFARBE,"
                    +"QOTCOLORIT= :QOTCOLORIT,"
                    +"QOTDESSIN= :QOTDESSIN,"
                    +"QOTBESCH= :QOTBESCH,"
                    +"QOTZUSTAND= :QOTZUSTAND,"
                    +"QOTGROE= :QOTGROE,"
                    +"QOTPRSFE= :QOTPRSFE,"
                    +"QOTPREINHT= :QOTPREINHT,"
                    +"QOTEINHEIT= :QOTEINHEIT,"
                    +"QOTPRSTK= :QOTPRSTK,"
                    +"QOTAUFTYP= :QOTAUFTYP,"
                    +"QOTAUFKRS= :QOTAUFKRS,"
                    +"QOTAUFLFD= :QOTAUFLFD,"
                    +"QOTAUFPOS= :QOTAUFPOS,"
                    +"QOTTP= :QOTTP,"
                    +"QOTANZEINH= :QOTANZEINH,"
                    +"QOTANZPR= :QOTANZPR,"
                    +"QOTANZAKT= :QOTANZAKT,"
                    +"QOTSKIPLOS= :QOTSKIPLOS,"
                    +"QOTZEILE= :QOTZEILE,"
                    +"QOTSPALTE= :QOTSPALTE,"
                    +"QOTORDER= :QOTORDER,"
                    +"QOTOSTEP= :QOTOSTEP,"
                    +"QOTORESULT= :QOTORESULT,"
                    +"QOTSRESULT= :QOTSRESULT,"
                    +"QOTRORDER= :QOTRORDER,"
                    +"QOTRSTEP= :QOTRSTEP,"
                    +"QOTAFOLGE= :QOTAFOLGE,"
                    +"QOTFILLER= :QOTFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("QOTMANDANT", OracleType.NVarChar).Value = dwData["QOTMANDANT"].ToString(); 
          or1.Parameters.Add("QOTPNRKRS", OracleType.NVarChar).Value = dwData["QOTPNRKRS"].ToString(); 
          or1.Parameters.Add("QOTPLFDNR", OracleType.NVarChar).Value = dwData["QOTPLFDNR"].ToString(); 
          or1.Parameters.Add("QOTPSTEP", OracleType.NVarChar).Value = dwData["QOTPSTEP"].ToString(); 
          or1.Parameters.Add("QOTLFDNR", OracleType.NVarChar).Value = dwData["QOTLFDNR"].ToString(); 
          or1.Parameters.Add("QOTNEUB", OracleType.NVarChar).Value = dwData["QOTNEUB"].ToString(); 
          or1.Parameters.Add("QOTNEUD", OracleType.NVarChar).Value = dwData["QOTNEUD"].ToString(); 
          or1.Parameters.Add("QOTAENB", OracleType.NVarChar).Value = dwData["QOTAENB"].ToString(); 
          or1.Parameters.Add("QOTAEND", OracleType.NVarChar).Value = dwData["QOTAEND"].ToString(); 
          or1.Parameters.Add("QOTAENZL", OracleType.NVarChar).Value = dwData["QOTAENZL"].ToString(); 
          or1.Parameters.Add("QOTARTST", OracleType.NVarChar).Value = dwData["QOTARTST"].ToString(); 
          or1.Parameters.Add("QOTKUNDNR", OracleType.NVarChar).Value = dwData["QOTKUNDNR"].ToString(); 
          or1.Parameters.Add("QOTWERK", OracleType.NVarChar).Value = dwData["QOTWERK"].ToString(); 
          or1.Parameters.Add("QOTABT", OracleType.NVarChar).Value = dwData["QOTABT"].ToString(); 
          or1.Parameters.Add("QOTART", OracleType.NVarChar).Value = dwData["QOTART"].ToString(); 
          or1.Parameters.Add("QOTVAR", OracleType.NVarChar).Value = dwData["QOTVAR"].ToString(); 
          or1.Parameters.Add("QOTFARBE", OracleType.NVarChar).Value = dwData["QOTFARBE"].ToString(); 
          or1.Parameters.Add("QOTCOLORIT", OracleType.NVarChar).Value = dwData["QOTCOLORIT"].ToString(); 
          or1.Parameters.Add("QOTDESSIN", OracleType.NVarChar).Value = dwData["QOTDESSIN"].ToString(); 
          or1.Parameters.Add("QOTBESCH", OracleType.NVarChar).Value = dwData["QOTBESCH"].ToString(); 
          or1.Parameters.Add("QOTZUSTAND", OracleType.NVarChar).Value = dwData["QOTZUSTAND"].ToString(); 
          or1.Parameters.Add("QOTGROE", OracleType.NVarChar).Value = dwData["QOTGROE"].ToString(); 
          or1.Parameters.Add("QOTPRSFE", OracleType.NVarChar).Value = dwData["QOTPRSFE"].ToString(); 
          or1.Parameters.Add("QOTPREINHT", OracleType.NVarChar).Value = dwData["QOTPREINHT"].ToString(); 
          or1.Parameters.Add("QOTEINHEIT", OracleType.NVarChar).Value = dwData["QOTEINHEIT"].ToString(); 
          or1.Parameters.Add("QOTPRSTK", OracleType.NVarChar).Value = dwData["QOTPRSTK"].ToString(); 
          or1.Parameters.Add("QOTAUFTYP", OracleType.NVarChar).Value = dwData["QOTAUFTYP"].ToString(); 
          or1.Parameters.Add("QOTAUFKRS", OracleType.NVarChar).Value = dwData["QOTAUFKRS"].ToString(); 
          or1.Parameters.Add("QOTAUFLFD", OracleType.NVarChar).Value = dwData["QOTAUFLFD"].ToString(); 
          or1.Parameters.Add("QOTAUFPOS", OracleType.NVarChar).Value = dwData["QOTAUFPOS"].ToString(); 
          or1.Parameters.Add("QOTTP", OracleType.NVarChar).Value = dwData["QOTTP"].ToString(); 
          or1.Parameters.Add("QOTANZEINH", OracleType.NVarChar).Value = dwData["QOTANZEINH"].ToString(); 
          or1.Parameters.Add("QOTANZPR", OracleType.NVarChar).Value = dwData["QOTANZPR"].ToString(); 
          or1.Parameters.Add("QOTANZAKT", OracleType.NVarChar).Value = dwData["QOTANZAKT"].ToString(); 
          or1.Parameters.Add("QOTSKIPLOS", OracleType.NVarChar).Value = dwData["QOTSKIPLOS"].ToString(); 
          or1.Parameters.Add("QOTZEILE", OracleType.NVarChar).Value = dwData["QOTZEILE"].ToString(); 
          or1.Parameters.Add("QOTSPALTE", OracleType.NVarChar).Value = dwData["QOTSPALTE"].ToString(); 
          or1.Parameters.Add("QOTORDER", OracleType.NVarChar).Value = dwData["QOTORDER"].ToString(); 
          or1.Parameters.Add("QOTOSTEP", OracleType.NVarChar).Value = dwData["QOTOSTEP"].ToString(); 
          or1.Parameters.Add("QOTORESULT", OracleType.NVarChar).Value = dwData["QOTORESULT"].ToString(); 
          or1.Parameters.Add("QOTSRESULT", OracleType.NVarChar).Value = dwData["QOTSRESULT"].ToString(); 
          or1.Parameters.Add("QOTRORDER", OracleType.NVarChar).Value = dwData["QOTRORDER"].ToString(); 
          or1.Parameters.Add("QOTRSTEP", OracleType.NVarChar).Value = dwData["QOTRSTEP"].ToString(); 
          or1.Parameters.Add("QOTAFOLGE", OracleType.NVarChar).Value = dwData["QOTAFOLGE"].ToString(); 
          or1.Parameters.Add("QOTFILLER", OracleType.NVarChar).Value = dwData["QOTFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
